/*
 * @Descripttion: 患者获取预约列表
 * @version: 1.0
 * @Author: 自由如风
 * @Date: 2021-05-05 09:30:10
 * @LastEditors: 自由如风
 * @LastEditTime: 2021-05-05 10:58:28
 */

const DB = require('../../lib/DB')
const { Success, Fail } = require('../../lib/Response')

module.exports = async function (ctx, next) {
    try {
        const foresee = (await DB.models.foresee.findAll({
            where: { patient_id: ctx.session.patient.id }, limit: 30, include: [
                {
                    model: DB.models.user,
                    as: 'doctor'
                },
                {
                    model: DB.models.patient,
                    as: 'patient'
                }
            ], order: [['createdAt', 'desc']]
        })).map(e => e.toJSON())
        ctx.body = new Success(foresee)
        await next();
    } catch (e) {
        ctx.body = new Fail(e.message)
    }
}
